define(function () {

    var self,
        userInfo,
        footData = {
            index: 0
        }
    ;

    app.newModule({

        init: function () {
            self = this;
            self.mData = {};
            self.searchData = {
                keyword: ''
            };
            userInfo = app.userInfos.sysUser;
            self._super({
                _tag: 'p_gwat171', // key, 对象放进pageModule
                _sliderId: 'slider', // tabs
                _refreshAutoInit: true //自动加载刷新控件
            }, win);

        },
        _initRefresh: function () { // 实例化刷新组件
            if (self._refreshIds.length == 0) {
                self._refreshIds = ['scrollN', 'scrollY', 'scrollX'];
                self._refreshVueOpts = {
                    data: {
                        others: {
                            SID: userInfo.ID,
                            ORGID: userInfo.ORG_ID
                        }
                    }
                };
            }
            this._super(win);
        },
        _refreshCb: function (goods) {// 刷新组件回调函授
            var _super = this._super;
            app.ajax({
                xurl: "api/wx/gwat171/getGwbhData",
                xdata: {
                    page: goods.page + 1,
                    limit: goods.limit,
                    GWBHACTI: goods.type.replace('scroll', ''),
                    keyword: self.searchData.keyword
                },
                cb: function (result) {
                    if (result.ok) {
                        var data = result.data;
                        for (var i = 0; i < data.data.length; i++) {
                            data.data[i].checked = false;
                        }
                        goods.data.pushArray(data.data, goods.page == 0);

                        _super({
                            obj: goods,
                            dataLen: data.data.length,
                            nodata: self._refreshIndex == 0 ? '无未确认商机主题...' : (self._refreshIndex == 1 ? '无已确认商机主题...' : '无已作废商机主题...')
                        });
                    }
                }
            });
        },
        _slide: function (i) {
            footData.index = i;
        },
        _search: function (data) {
            self.searchData.keyword = data.keyword.trim();
            self._refresh();
        },
        _lazy: function () {
            this._super();

            $('#allCheck').click(function () { //全选
                var items = self._getRefreshObj().data;
                if ($('#allCheck').is(':checked')) {
                    $('#pullRefresh input[type=checkbox]').prop('checked', true);
                    for (var i = 0; i < items.length; i++) {
                        var item = items[i];
                        if (userInfo.ORG_ID && item.GWBHORIG && userInfo.ORG_ID != item.GWBHORIG) {
                            item.checked = true;
                        }
                    }
                } else {
                    $('#pullRefresh input[type=checkbox]').prop('checked', false);
                    for (var i = 0; i < items.length; i++) {
                        items[i].checked = false;
                    }
                }
            });
        },
        _ready: function () {
            Vue.component('gwat171-listitem', {
                template: app.getByid(doc, 'item-template'),
                props: {
                    model: Array,
                    other: Object
                },
                methods: {
                    statueN: function (item) {
                        if (item.GWBHACTI == 'N') {
                            return true;
                        } else {
                            return false;
                        }
                    },
                    statueY: function (item) {
                        if (item.GWBHACTI == 'Y') {
                            return true;
                        } else {
                            return false;
                        }
                    },
                    statueImg: function (item) {
                        if (item.GWBHACTI == 'Y') {
                            return 'comfirom';
                        } else if (item.GWBHACTI == 'N') {
                            return 'nonComfirom';
                        } else {
                            return '';
                        }
                    },
                    showDetail: function (item) {
                        app.openPage({
                            src: "gwat171/gwat171-info.html",
                            argsKey: 'gwat171_01_page',
                            args: item
                        });
                    },
                    confirm: function (item) {

                        var _data = {
                            CHARACTERISTICS: []
                        };

                        _data.CHARACTERISTICS.push({
                            GWBHACTI: 'Y',
                            GWBHENT: item.GWBHENT,
                            GWBHID: item.GWBHID,
                            GWBHSEQ: item.GWBHSEQ,
                            GWBHNAME: item.GWBHNAME

                        });

                        app.ajax({
                            xurl: "api/wx/gwat171/updateByKey",
                            xdata: {
                                obj: app.jsonString(_data)
                            },
                            confirm: {
                                msg: '是否确认？'
                            },
                            cb: function (result) {
                                if (result.ok) {
                                    app.alert({
                                        msg: "确认成功",
                                        ok: function () {
                                            self._refresh();
                                        }
                                    });
                                }
                            }
                        });
                    },
                    reconfirm: function (item) {
                        var _data = {
                            CHARACTERISTICS: []
                        };

                        _data.CHARACTERISTICS.push({
                            GWBHACTI: 'N',
                            GWBHID: item.GWBHID,
                            GWBHSEQ: item.GWBHSEQ,
                            GWBHENT: item.GWBHENT,
                            GWBHNAME: item.GWBHNAME
                        });

                        app.ajax({
                            xurl: "api/wx/gwat171/updateByKey",
                            xdata: {
                                obj: app.jsonString(_data)
                            },
                            confirm: {
                                msg: '是否取消？'
                            },
                            cb: function (result) {
                                if (result.ok) {
                                    app.alert({
                                        msg: "取消成功",
                                        ok: function () {
                                            self._refresh();
                                        }
                                    });
                                }
                            }
                        })
                    },
                    del: function (item) {
                        app.confirm({
                            msg: '是否作废？',
                            ok: function (e) {
                                var _data = {
                                    CHARACTERISTICS: []
                                };
                                _data.CHARACTERISTICS.push({
                                    GWBHACTI: 'X',
                                    GWBHID: item.GWBHID,
                                    GWBHSEQ: item.GWBHSEQ,
                                    GWBHENT: item.GWBHENT,
                                    GWBHNAME: item.GWBHNAME
                                });

                                app.ajax({
                                    xurl: "api/wx/gwat171/updateByKey",
                                    xdata: {
                                        obj: app.jsonString(_data)
                                    },
                                    cb: function (result) {
                                        if (result.ok) {
                                            app.alert({
                                                msg: "作废成功",
                                                ok: function () {
                                                    self._refresh();
                                                }
                                            });
                                        }
                                    }
                                })
                            }
                        });
                    }
                }
            });
        }
    });

});